/*
 * @Description: 
 * @Autor: starzhou
 * @Date: 2020-08-31 20:34:35
 * @LastEditTime: 2020-09-09 19:28:44
 */
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store/index';
import ElementUI from 'element-ui';
import echarts from 'echarts';
import axios from 'axios';
import bus from './utils/bus.js';
// require ("./utils/mock.js");

import Api from './utils/api.js';
import {resetRouter} from './router';
import Router from 'vue-router';
//使用剪切板
import VueClipboard  from 'vue-clipboard2'

Vue.use( VueClipboard )

Vue.config.productionTip = false;

Vue.use(ElementUI);
Vue.prototype.$echarts = echarts;
Vue.prototype.$axios = axios;
Vue.prototype.$Api = Api;
Vue.prototype.$bus = bus;

const routerOther = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerOther.call(this, location).catch(err => err)
}

router.beforeEach(async (to, from, next) => {
    if (to.path === '/login') {
        next();
    } else {
        var menus = store.state.menus
        if (menus) {
            next();
        } else {
            var token = sessionStorage.getItem('apptoken')
            if (token) {
                await store.dispatch('getInfo').then(() => {
                    next();
                })
                resetRouter()
                // const routes = resetRouter(store.state.menus)
                // router.addRoutes(routes)
            } else {
                next({
                    path: '/login',
                });
            }
        }
    }
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h =>h(App)
}).$mount('#app')
